
#include <atomic>
#include <chrono>
#include <glog/logging.h>
#include <thread>
#include <vector>

std::vector<int> data;
std::atomic<bool> data_ready(false);

void reader_thread()
{
    while (!data_ready.load()) {
        LOG(INFO) << "Waiting ...";
        std::this_thread::sleep_for(std::chrono::milliseconds(1));
    }
    LOG(INFO) << "data: " << data[0];
}

void writer_thread()
{
    std::this_thread::sleep_for(std::chrono::milliseconds(3));
    data.push_back(15);
    data_ready.store(true);
}

int count = 0;

void foo(int a, int b)
{
    if (a > b) {
        ++count;
    }
    // LOG(INFO) << a << " : " << b;
}

int get_num()
{
    static int i = 0;
    return ++i;
}

int main(int argc, char* argv[])
{
    google::SetStderrLogging(google::LogSeverity(FLAGS_minloglevel));
    google::InitGoogleLogging(argv[0]);

    std::thread t1(reader_thread);
    std::thread t2(writer_thread);

    t1.join();
    t2.join();

    for (int i = 0; i < 1000000000; ++i) {
        foo(get_num(), get_num());
    }
    LOG(INFO) << "count: " << count;
    return 0;
}